2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Graphics;
8 namespace SuperPolarity
10 static class ActorManager
14 static int OutlierBounds;
15 static List<Actor> Actors;
20 Actors = new List<Actor>();
23 static public void CheckIn(Actor actor)
28 static public void CheckOut(Actor actor)
33 static public void Update(GameTime gameTime)
37 foreach (Actor actor in Actors)
39 actor.Update(gameTime);
43 static public void Draw(SpriteBatch spriteBatch)
45 foreach (Actor actor in Actors)
47 actor.Draw(spriteBatch);
51 static void CheckActors()
54 foreach (Actor actor in Actors)
57 foreach (Actor other in Actors.Skip(i))
59 CheckCollision(actor, other);
61 if (actor.GetType().IsSubclassOf(typeof(Ship)) && other.GetType().IsSubclassOf(typeof(Ship)))
63 CheckMagnetism((Ship)actor, (Ship)other);
69 static void CheckCollision(Actor actor, Actor other)
74 static void CheckMagnetism(Ship actor, Ship other)
76 if (actor.CurrentPolarity != Ship.Polarity.Neutral && other.CurrentPolarity != Ship.Polarity.Neutral)
78 var dy = other.Position.Y - actor.Position.Y;
79 var dx = other.Position.X - actor.Position.X;
80 var linearDistance = Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2));
81 var angle = (float) Math.Atan2(dy, dx);
82 var otherAngle = (float)Math.Atan2(-dy, -dx);
84 if (linearDistance < actor.MagneticRadius || linearDistance < other.MagneticRadius)
86 actor.Magnetize(other, (float)linearDistance, angle);
87 other.Magnetize(actor, (float)linearDistance, otherAngle);
92 static void CheckOutliers()
94 for (var i = Actors.Count; i > 0; i--)
96 var actor = Actors[i-1];
97 if (actor.Position.X < -OutlierBounds || actor.Position.Y < -OutlierBounds ||
98 actor.Position.X > Game.GraphicsDevice.Viewport.Width + OutlierBounds ||
99 actor.Position.Y > Game.GraphicsDevice.Viewport.Height + OutlierBounds)
106 internal static void SetGame(Game game)